package com.splic.common.utils;

import com.splic.common.exception.BusinessException;
import com.splic.common.utils.security.Md5Utils;

import java.util.Random;
import java.util.UUID;

public class RandomCodeUtil {

    public static String code(){
        return getUUID().substring(0,20);
    }

    public static String havePrefixCodeTwenty(String prefix){
        return prefix.toUpperCase()+ getUUID().substring(0,20);
    }

    public static String havePrefixCode(String prefix){
        if(StringUtils.isEmpty(prefix)){
            throw new BusinessException("前缀不能为空");
        }
        return prefix.toUpperCase()+getUUID().substring(prefix.length());
    }


    public static String havePrefixOrderNo(String prefix){
        if(StringUtils.isEmpty(prefix)){
            throw new BusinessException("前缀不能为空");
        }
        return prefix.toUpperCase()+ getUUID().substring(prefix.length());
    }

    public static String getUUID(){
       return Md5Utils.hash(UUID.randomUUID().toString().replace("-","")).toUpperCase();
    }

    public static String haveUserIdentify(String prefix){
        if(StringUtils.isEmpty(prefix)){
            throw new BusinessException("前缀不能为空");
        }
        return prefix.toUpperCase() +DateUtils.dateTime()+ getUUID().substring(12);
    }

    public static String identifyCode(String prefix){
        return prefix + DateUtils.dateTimeNow()+ MathUtils.randomDigitNumber(2);
    }

    public static void main(String[] args) {
        for(int i = 0;i<100;i++){
            System.out.println(identifyCode("UE"));
            System.out.println(identifyCode("DE"));
        }

    }
}
